<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.text.DateFormat"%>
<%@page import="util.Utilities"%>
<%@page import="beans.Teacherbean"%>
<%@page import="dao.Teacher"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="/WEB-INF/tlds/pagediv" prefix="page" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>教师列表</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<link href="./css/mytable.css" rel="stylesheet" type="text/css">
		<style type="text/css">

#outside {
	margin:0 auto;
	text-align:center;
}
</style>
		<title>显示所有教师</title>
		
	</head>
	<body>
	<%
		String[] sexStr = {"男","女"};
		String[] rankStr = {"普通教师","年级组长"};
		DateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
	%>
		<div id="outside">
			<table id="mytable" >
				<caption>
					所有老师列表
				</caption>
				<tr>
					<th scope="col">
						编号
					</th>
					<th scope="col">
						姓名
					</th>
					<th scope="col">
						性别
					</th>
					<th scope="col">
						出生日期
					</th>
					<th scope="col">
						所在年级
					</th>
					<th scope="col">
						所教科目
					</th>
					<th scope="col">
						职位
					</th>
					<th scope="col">
						操作
					</th>
				</tr>
				<%
					Teacherbean teacherService = new Teacherbean();
					request.setAttribute("counts",teacherService.getTeacherCounts());
					request.setAttribute("pageSize",teacherService.getPageSize());
					List<Teacher> list = (List<Teacher>)request.getAttribute("data");
					if(list == null){
						list = teacherService.getTeachers(1);
						}
						if(list != null){							
							StringBuffer buffer = null;
							String grade = null, courseName=null, birthString=null;
                            for (int i=0;i<list.size();i++) {
                        		buffer = new StringBuffer();
                        		int x = Integer.parseInt(list.get(i).getSex());
                        		int y = Integer.parseInt(list.get(i).getRank()); 
                        		grade = Utilities.getGradeName(list.get(i).getCourseid().substring(0,2));
                        		courseName = Utilities.getCourseName(list.get(i).getCourseid().substring(2));
                        		birthString = formater.format(list.get(i).getBirthdate());
                        		buffer.append("<tr><td>").append(i+1).append("</td><td>").append(list.get(i).getName())
                        		.append("</td><td>").append(sexStr[x]).append("</td><td>").append(birthString)
                        		.append("</td><td>").append(grade).append("</td><td>").append(courseName).append("</td><td>").append(rankStr[y])
                        		.append("</td><td><a href='./admin/modifyTeacher.jsp?teacherId=").append(list.get(i).getTeacherid())
                        		.append("' target='_blank'>修改</a></td></tr>");
                        		out.write(buffer.toString());
                            }
						 } else {
									out.println("<tr><td colspan='8'>目前没有满足要求的数据</td></tr>");
                         }
                        %>
			</table>
			<page:divide pageNum="${pageNum}" pageSize="${pageSize}" counts="${counts}"
                     url="./servlet/TeacherDividePageServlet">                
        </page:divide>
		</div>
		</body>
</html>
